package com.shigi.knapsack;

/**
 * Created by Miroslav Šiagi on 29/09/14.
 */
public class KnapsackInstance extends com.shigi.problem.Instance {

    private int numberOfItems;
    private int totalWeight;

    private KnapsackItem[] knapsackItems;

    public KnapsackInstance(int id) {
        super(id);
    }

    public KnapsackInstance(KnapsackInstance anotherKnapsackInstance) {
        super(anotherKnapsackInstance.getId());
        this.numberOfItems = anotherKnapsackInstance.getNumberOfItems();
        this.totalWeight = anotherKnapsackInstance.getTotalWeight();
        this.knapsackItems = new KnapsackItem[this.numberOfItems];
        for (int i = 0; i < this.numberOfItems; i++) {
            this.knapsackItems[i] = new KnapsackItem(anotherKnapsackInstance.knapsackItems[i].getId());
            this.knapsackItems[i].setValue(anotherKnapsackInstance.knapsackItems[i].getValue());
            this.knapsackItems[i].setWeight(anotherKnapsackInstance.knapsackItems[i].getWeight());
        }
    }

    public int getNumberOfItems() {
        return numberOfItems;
    }

    public void setNumberOfItems(int numberOfItems) {
        this.numberOfItems = numberOfItems;
    }

    public int getTotalWeight() {
        return totalWeight;
    }

    public void setTotalWeight(int totalWeight) {
        this.totalWeight = totalWeight;
    }

    public KnapsackItem[] getKnapsackItems() {
        return knapsackItems;
    }

    public void setKnapsackItems(KnapsackItem[] knapsackItems) {
        this.knapsackItems = knapsackItems;
    }

    public int getSumOfWeights() {
        int sum = 0;
        for(KnapsackItem knapsackItem : this.knapsackItems) {
            sum += knapsackItem.getWeight();
        }
        return sum;
    }
}
